import grpc
import inventory_pb2
import inventory_pb2_grpc

def create_order(product_id, quantity):
    # 调用库存服务
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = inventory_pb2_grpc.InventoryServiceStub(channel)
        response = stub.DeductStock(inventory_pb2.DeductRequest(
            product_id=product_id, quantity=quantity
        ))
        if response.success:
            print("订单创建成功！")
        else:
            print(f"下单失败：{response.message}")

if __name__ == '__main__':
    create_order("product_001", 5)  # 测试下单5件商品